<template>
  <!-- 系统管理 -->
  <div class="app-container">
    <div class="mainbox">
      <!-- 顶部操作 -->
      <div class="filter-container">
        <el-form ref="filterFormRef" :inline="true" :model="filterForm">
          <el-form-item label="姓名:" prop="name">
            <el-input
              v-model.trim="filterForm.name"
              class="filter-item limit"
              style="width: 200px;margin-right:10px"
              maxlength="30"
              clearable
              placeholder="请输入姓名"
              @keyup.enter.native="$_handleFilter"
            />
          </el-form-item>
          <el-form-item label="性别:" prop="gender">
            <el-select v-model.trim="filterForm.gender" placeholder="请选择" :clearable="true">
              <el-option
                v-for="dict in dict.type.sex"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="企业名称:" prop="companyName">
            <el-input
              v-model.trim="filterForm.companyName"
              class="filter-item limit"
              style="width: 200px;margin-right:10px"
              maxlength="30"
              clearable
              placeholder="请输入企业名称"
              @keyup.enter.native="$_handleFilter"
            />
          </el-form-item>
          <el-form-item label="企业类别:" prop="companyCategoryCode">
            <el-select v-model.trim="filterForm.companyCategoryCode" placeholder="请选择" :clearable="true">
              <el-option
                v-for="dict in dict.type.QYLX"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="联系人:" prop="contactsName">
            <el-input
              v-model.trim="filterForm.contactsName"
              class="filter-item limit"
              style="width: 200px;margin-right:10px"
              maxlength="30"
              clearable
              placeholder="请输入联系人"
              @keyup.enter.native="$_handleFilter"
            />
          </el-form-item>
          <el-form-item label="推荐单位:" prop="recommendedUnit">
            <el-input
              v-model.trim="filterForm.recommendedUnit"
              class="filter-item limit"
              style="width: 200px;margin-right:10px"
              maxlength="30"
              clearable
              placeholder="请输入推荐单位"
              @keyup.enter.native="$_handleFilter"
            />
          </el-form-item>
        </el-form>
        <div class="flex-1" />
        <el-button type="primary" @click="$_handleFilter">查询</el-button>
        <el-button @click="$_handleReset">重置</el-button>

      </div>
      <!-- 表格 -->
      <div class="table-container table-fullscreen">
        <div class="table-opt-container">
          <el-button
            v-permission="['COUNTYSAGELIST_ADD_BUTTON']"
            type="primary"
            icon="el-icon-plus"
            @click="handleAdd"
          >
            新增
          </el-button>
          <el-button
            v-permission="['COUNTYSAGELIST_DOWNLOAD_BUTTON']"
            icon="el-icon-download"
            @click="handleExport('d')"
          >
            下载模板
          </el-button>
          <el-button
            v-permission="['COUNTYSAGELIST_IMPORT_BUTTON']"
            icon="el-icon-folder-add"
            type="primary"
            @click="$_handleImport()"
          >
            导入
          </el-button>
          <el-button
            v-permission="['COUNTYSAGELIST_EXPORT_BUTTON']"
            icon="el-icon-folder-remove"
            type="primary"
            @click="handleExport()"
          >
            导出
          </el-button>
          <div class="flex-1" />
          <dt-dialog-column :columns="columns" @queryTable="getList" />
        </div>
        <el-table
          ref="table"
          v-loading="MX_listLoading"
          :data="MX_list"
          border
          highlight-current-row
          :row-key="$_getRowKey"
          style="width: 100%;text-align:center"
          :header-cell-style="MX_headerCellStyle"
        >
          <template slot="empty">
            <p>{{ $store.getters.dataText }}</p>
          </template>
          <el-table-column
            fixed="left"
            type="index"
            label="序号"
            width="70"
            align="center"
            :index="$_tableIndex"
          />
          <el-table-column
            v-for="item in columns"
            :key="item.prop"
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
            :min-width="item.minWidth"
            :formatter="item.formatter"
            align="center"
          />
          <el-table-column
            :key="Math.random()"
            fixed="right"
            label="操作"
            width="220px"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                v-permission="['COUNTYSAGELIST_DETAIL_BUTTON']"
                size="mini"
                class="tBtn"
                @click="$_handleDetail(scope.row)"
              >详情</el-button>
              <el-button
                v-permission="['COUNTYSAGELIST_UPDATE_BUTTON']"
                size="mini"
                class="tBtn"
                @click="handleEdit(scope.row)"
              >修改</el-button>
              <el-button
                v-permission="['COUNTYSAGELIST_DEL_BUTTON']"
                size="mini"
                type="danger"
                class="tBtn"
                @click="handleDelete(scope.row.venerableId)"
              >删除</el-button>
              <el-button
                v-permission="['COUNTYSAGELIST_HISTORY_BUTTON']"
                size="mini"
                class="tBtn"
                @click="goto(scope.row.venerableId, 'h')"
              >历史投资</el-button>
              <el-button
                v-permission="['COUNTYSAGELIST_FOLLOWUP_BUTTON']"
                size="mini"
                class="tBtn"
                @click="goto(scope.row.venerableId)"
              >回访记录</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <dt-pagination
          v-show="MX_total > 0"
          :total="MX_total"
          :page.sync="MX_pageNav.pageNo"
          :limit.sync="MX_pageNav.pageSize"
          @pagination="getList"
        />
      </div>
      <DialogForm ref="dialogForm" labelWidth="140px" :formDesignList="formDesignList" />
      <dtDialog
        title="导入"
        class="get-page-form-import-dialog"
        :visible.sync="MX_fileUploadVisible"
        width="620px"
        :is-loading="MX_uploadLoading"
        @closeDialog="MX_fileUploadVisible = false"
        @comfirmBtn="$_importDataSave(importApi)"
      >
        <el-form slot="content">
          <div class="">
            <dt-importFile ref="dtImportFileRef" :down-load-template="handleImportTemplate" :type="fileName" />
          </div>
        </el-form>
      </dtDialog>
    </div>
  </div>
</template>
<script>
import intservApi from '@/api/investment/intserv'
import DialogForm from '@/views/investment/components/DialogForm'
import commonList from "@/utils/mixins/investment/commonList";

export default {
  dicts: ['sex', 'QYLX'],
  name: 'CountySageList',
  components: {
    DialogForm
  },
  mixins: [commonList],
  data() {
    const _this = this
    return {
      filterForm: {
        name: '',
        gender: '',
        companyName: '',
        contactsName: '',
        recommendedUnit: '',
        companyCategoryCode: ''
      },
      fileName: '乡贤数据导入',
      handleImportTemplate: intservApi.downloadCountySage,
      importApi: intservApi.importCountySage,
      // 列信息
      columns: [
        { prop: 'recommendedUnit', label: `推荐单位`, minWidth: '100px' },
        { prop: 'name', label: `姓名` },
        { prop: 'gender', label: `性别`, formatter: function(row) {
            return _this.dict.label.sex[row.gender] || ''
          } },
        { prop: 'bornDate', label: `出生年月`, width: '140px'  },
        { prop: 'origin', label: `籍贯`, width: '80px'  },
        { prop: 'companyCategoryCode', label: `企业类别`, minWidth: '100px', formatter: function(row) {
            return _this.dict.label.QYLX[row.companyCategoryCode] || ''
          } },
        { prop: 'companyName', label: `就职单位/企业名称`, minWidth: '100px' },
        { prop: 'companyPost', label: `职务/职称`, minWidth: '100px' },
        { prop: 'contactsPhone', label: `联系电话`, width: '140px' },
        { prop: 'companyAddress', label: `现工作地址`, minWidth: '100px' },
        { prop: 'highName', label: `高中就读学校`, minWidth: '100px' },
        { prop: 'universityName', label: `高等教育就读院校`, minWidth: '100px' },
        { prop: 'industryCategory', label: `行业类别/研究领域`, minWidth: '100px' },
        { prop: 'fillUnits', label: `填报单位`, minWidth: '100px' },
        { prop: 'contactsName', label: `联系人`, width: '100px'  },
        { prop: 'phone', label: `联系电话`, width: '140px' }
      ],
      formDesignList: [
        { type: 'text', prop: 'recommendedUnit', label: `推荐单位`, rules: [{ required: true, message: '请输入推荐单位', trigger: 'blur' }] },
        { type: 'text', prop: 'name', label: `姓名`, rules: [{ required: true, message: '请输入姓名', trigger: 'blur' }] },
        { type: 'select', prop: 'gender', label: `性别`, dictTypeCode: 'sex', rules: [{ required: true, message: '请选择性别', trigger: 'change' }] },
        { type: 'month', prop: 'bornDate', label: `出生年月`, format: 'yyyy-MM', rules: [{ required: true, message: '请选择出生年月', trigger: 'blur' }] },
        { type: 'text', prop: 'origin', label: `籍贯`, rules: [{ required: true, message: '请输入籍贯', trigger: 'blur' }] },
        { type: 'select', prop: 'companyCategoryCode', label: `企业类别`, dictTypeCode: 'QYLX', rules: [{ required: true, message: '请选择企业类别', trigger: 'change' }] },
        { type: 'text', prop: 'companyName', label: `就职单位/企业名称`, rules: [{ required: true, message: '请输入就职单位/企业名称', trigger: 'blur' }] },
        { type: 'text', prop: 'companyPost', label: `职务/职称`, rules: [{ required: true, message: '请输入职务/职称', trigger: 'blur' }] },
        { type: 'text', prop: 'contactsPhone', label: `联系电话`, rules: [{ required: true, message: '请输入联系电话', trigger: 'blur' }, { pattern: /^(1[3456789]\d{9})$/, message: '请输入有效的联系电话', trigger: 'blur' }] },
        { type: 'text', prop: 'companyAddress', label: `现工作地址`, rules: [{ required: true, message: '请输入现工作地址', trigger: 'blur' }] },
        { type: 'text', prop: 'highName', label: `高中就读学校`, rules: [{ required: true, message: '请输入高中就读学校', trigger: 'blur' }] },
        { type: 'text', prop: 'universityName', label: `高等教育就读院校`, rules: [{ required: true, message: '请输入高等教育就读院校', trigger: 'blur' }] },
        { type: 'text', prop: 'industryCategory', label: `行业类别/研究领域`, rules: [{ required: true, message: '请输入行业类别/研究领域', trigger: 'blur' }] },
        { type: 'text', prop: 'fillUnits', label: `填报单位`, rules: [{ required: true, message: '请输入填报单位', trigger: 'blur' }] },
        { type: 'text', prop: 'contactsName', label: `联系人`, rules: [{ required: true, message: '请输入联系人', trigger: 'blur' }] },
        { type: 'text', prop: 'phone', label: `联系电话`, rules: [{ required: true, message: '请输入联系电话', trigger: 'blur' }, { pattern: /^(1[3456789]\d{9})$/, message: '请输入有效的联系电话', trigger: 'blur' }] }
      ],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取页面列表
    getList() {
      this.$_getList(intservApi.getCountySageList,{
        ...this.filterForm,
        ...this.MX_pageNav
      })
    },
    // 编辑按钮
    handleEdit(data) {
      this.$refs.dialogForm.open('update', intservApi.updateCountySageItem, data || this.MX_applicationMsg)
    },
    // 添加按钮
    handleAdd() {
      this.$refs.dialogForm.open('add', intservApi.addCountySageItem)
    },
    // 删除按钮
    handleDelete(id) {
      this.$_handleDelete(intservApi.delCountySageItem, [id], 'venerableIds')
    },
    /** 导出/下载按钮操作 */
    handleExport(type = 'export') {
      if (type === 'export'){
        this.$_handleDownload(intservApi.exportCountySage, '乡贤列表', this.filterForm, '导出');
      }else{
        this.$_handleDownload(this.handleImportTemplate, `${this.fileName}模板`);
      }
    },
    goto(id, type){
      this.$router.push(`/investment/intserv/${type === 'h' ? 'HistoryInvestmentList' : 'FollowUpList'}?id=${id}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.tBtn{
  margin-top: 3px;
  margin-bottom: 3px;
}
</style>
